<?
require_once("../index.php");

 
$db = Zend_Db::factory($config->db);
 
$users = new Zend_Config_Ini('users.ini');
 
try {
    echo "\n>>> Delete acl_users table\n";
    $db->query('DROP TABLE IF EXISTS `acl_users`');
} catch (Exception $e) {
    echo $e->getMessage();
}
 
try {
    echo "\n>>> Re-creating acl_users table\n";
    $db->query('CREATE TABLE `acl_users` (
                `uid` INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
                `role_id` INTEGER(4) NOT NULL,
                `user_name` VARCHAR(64) NOT NULL UNIQUE);
               ');
 
    foreach ($users as $key => $value) {
        $sql = $db->query('SELECT `role_id` FROM `acl_roles` WHERE `role_name` = "' . $value . '"');
        $role = $sql->fetchObject();
        $db->query('INSERT INTO `acl_users` (role_id, user_name) VALUES (' . $role->role_id . ', "' . $key . '")');
    }
 
    echo "\n>>> ACL Users rebuild complete\n\n";
} catch (Exception $e) {
    echo $e->getMessage();
}